package com.jdyfy.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.jdyfy.constant.Constants;
import com.jdyfy.entity.Dict;
import com.jdyfy.entity.Menu;
import com.jdyfy.mapper.DictMapper;
import com.jdyfy.result.Result;
import com.jdyfy.service.MenuService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

@RestController
@RequestMapping("/jdyfy")
@Slf4j
public class MenuController {

    @Autowired
    private MenuService menuService;

    @Autowired
    private DictMapper dictMapper;

    // 获取所有菜单
    @GetMapping("/menu/findMenus")
    public Result<List<Menu>> findMenus(){
        return Result.success(menuService.findMenus());
    }

    //获取所有菜单的id（数组）用于权限管理时显示勾选信息的准确性
    @GetMapping("/findMenuIds")
    public Result<Stream<Long>> findMenuIds(){
        return Result.success(menuService.list().stream().map(Menu::getMenuId));
    }

    @GetMapping("/icons")
    public Result<List<Dict>> getIcons(){
        QueryWrapper<Dict> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("type", Constants.DICT_TYPE_ICON);
        return Result.success(dictMapper.selectList(null));
    }

}
